import { queryFakeTaskList, addFakeTaskList, removeFakeTaskList } from '../services/api';

export default {
  namespace: 'tasklist',

  state: {
    data: {
      list: [],
      pagination: {},
    },
    // 定义格式
    // tasklist: [],
    // visible: false,
  },


  effects: {
    // *fetch({ payload }, { call, put }) {
    //   const response = yield call(queryFakeTaskList, payload);
    //   yield put({
    //     type: 'queryTaskList',
    //     payload: Array.isArray(response) ? response : [],
    //   });
    // },
    *fetch({ payload }, { call,put }) {
      const response = yield call(queryFakeTaskList,payload);
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *add({ payload, callback }, { call, put }) {
      const response = yield call(addFakeTaskList, payload);
      yield put({
        type: 'save',
        payload: response,
      });
      if (callback) callback();
    },
    *remove({ payload, callback }, { call, put }) {
      const response = yield call(removeFakeTaskList, payload);
      yield put({
        type: 'save',
        payload: response,
      });
      if (callback) callback();
    },
    // *appendFetch({ payload }, { call, put }) {
    //   const response = yield call(queryFakeTaskList, payload);
    //   yield put({
    //     type: 'appendTaskList',
    //     payload: Array.isArray(response) ? response : [],
    //   });
    // },
  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        data: action.payload,
      };
    },
    // queryTaskList(state, action) {
    //   return {
    //     ...state,
    //     tasklist: action.payload,
    //   };
    // },
    // appendTaskList(state, action) {
    //   return {
    //     ...state,
    //     tasklist: state.tasklist.concat(action.payload),
    //   };
    // },
  },
};
